package com.ruoyi.eqmonitor.dispose.resolve;

import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import com.ruoyi.eqmonitor.dtos.OptDeviceDto;
import com.ruoyi.eqmonitor.utils.Constant;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * 设备告警处理
 *
 * @author dh
 */
@Slf4j
@Component
public class AlarmResolve implements MqttMessageResolve {

    private static final Logger dataLogger = LoggerFactory.getLogger("monitor_alarm");

    @Override
    public boolean support(int msgType) {
        return Constant.MqttMsgType.ALARM.getCode() == msgType;
    }

    // 改为自行判断报警
    @Override
    public boolean resolve(String snCode, OptDeviceDto deviceDto, JSONArray messageArray) {
        messageArray.parallelStream().forEach((obj) -> {
            JSONObject jsonObject = (JSONObject) obj;
            log.debug("snCode:{}, deviceCode: {}, 接收到报警实时数据:{}", snCode, deviceDto.getDeviceCode(), jsonObject);
            dataLogger.info("snCode:{}, deviceCode: {},接收到报警实时数据:{}", snCode, deviceDto.getDeviceCode(), jsonObject);
        });
        return true;
    }
}
